<?php
namespace app\index;

class common {
	// 图片上传处理  曹振威
	public static function picture($files) {
		if (isset($files)) {
			$info = $files->validate(['size' => 65678, 'ext' => 'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
			if ($info) {
				$a = $info->getSaveName();
				$imgp = str_replace("\\", "/", $a);
				$imgpath = 'uploads/' . $imgp;
				return $imgpath;
			} else {
				echo $files->getError();
			}
		} else {
			echo '未获取到文件信息';
		}
	}

	// 验证手机号格式  曹振威
	public static function check_mobile($phone = 0, $landline = 0) {
		if ($phone != 0) {
			preg_match('/^0?(13|14|15|17|18)[0-9]{9}$/', $phone, $matches);
			if (!$matches) {
				return array("ErrorCode" => 1, "ErrorMessage" => "不是电话号码");
			}
		}

		if ($landline != 0) {
			preg_match("/^(\d{3}-)(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$/", $landline, $matches);
			if (!$matches) {
				return array("ErrorCode" => 2, "ErrorMessage" => "座机号码有误");
			}
		}
	}

}
